﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Configuration;
using System.Data;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class CustomerController : Controller
    {
        //
        // GET: /Customer/

        public ActionResult Index()
        {
            var proxy = new Proxy.ServiceProxy();
            var agents = proxy.GetAllCustomers();
            return View(agents);
        }

        //
        // GET: /Customer/Details/5

        public ActionResult Details(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            var customer = proxy.GetCustomerById   (id);
            return View(customer);
        }

        //
        // GET: /Customer/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Customer/Create

        [HttpPost]
        public ActionResult Create(User customer)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.CreateCustomer(customer);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /Customer/Edit/5

        public ActionResult Edit(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            User cusomer = proxy.GetCustomerById(id);
            return View(cusomer);
        }
        

        //
        // POST: /Customer/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, User customer)
        {

            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.UpdateCustomer(customer);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /Customer/Delete/5

        public ActionResult Delete(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var customer = proxy.GetCustomerById(id);
            return View(customer);
        }

        //
        // POST: /Customer/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, User customerToBeDeleted)
        {

            ITgiService proxy = new Proxy.ServiceProxy();
            proxy.DeleteCustomerById(id);
            return RedirectToAction("Index");
           
        }
    }
}
